package com.deke.teacher.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.deke.entity.EduTeacherVo;
import com.deke.teacher.service.EduTeacherVoService;
import com.deke.teacher.service.OssService;
import com.deke.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * @author ：张恒（1371745897@qq.com）
 * @date ：Created in 2022/12/7 12:47
 * @description：
 * @modified By：
 * @version:
 */
@RestController
@RequestMapping("/cores/teacher")
@Api(tags = "讲师信息")
public class EduTeacherController {
    @Resource
    private EduTeacherVoService eduTeacherVoService;

    @Resource
    private OssService ossService;

    /**
     * @create by: 张恒
     * @description: 讲师信息的分页查询
     * @create time: 2023/1/30 14:19
     * @param eduTeacherVo 讲师信息的实体类
     * @param current 每页多少条
     * @param pageSize 几页
     * @return com.deke.vo.Result<com.baomidou.mybatisplus.core.metadata.IPage<com.deke.entity.EduTeacherVo>>
     */
    @PostMapping("/findTeacher/{current}/{pageSize}")
    @ApiOperation(value = "查询所有讲师的信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "current", value = "当前页码"),
            @ApiImplicitParam(name = "pageSize", value = "每页显示的条数")
    })
    public Result<IPage<EduTeacherVo>> findTeacher(@RequestBody EduTeacherVo eduTeacherVo,
                                                   @PathVariable Integer current,
                                                   @PathVariable Integer pageSize) {
        return eduTeacherVoService.queryByConditionPage(eduTeacherVo, current, pageSize);
    }


    /**
     * @create by: 张恒
     * @description: 讲师状态的修改
     * @create time: 2023/1/30 14:21
     * @param id 讲师id
     * @param status 讲师状态
     * @return com.deke.vo.Result
     */
    @PostMapping("/changeStatus/{id}/{status}")
    @ApiOperation(value = "修改讲师状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "讲师id"),
            @ApiImplicitParam(name = "status", value = "讲师状态")
    })
    public Result changeStatus(@PathVariable String id, @PathVariable String status) {
        return eduTeacherVoService.updateStatus(id, status);
    }


    /**
     * @create by: 张恒
     * @description: 讲师信息的修改
     * @create time: 2023/1/30 14:21
     * @param eduTeacherVo 讲师信息实体类
     * @return com.deke.vo.Result
     */
    @PostMapping("updateTeacher")
    @ApiOperation(value = "修改的方法")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "eduTeacherVo",value = "讲师信息实体类")
    })
    public Result updateTeacher(@RequestBody EduTeacherVo eduTeacherVo){
        return eduTeacherVoService.update(eduTeacherVo);
    }


    /**
     * @create by: 张恒
     * @description: 讲师添加
     * @create time: 2023/1/30 14:22
     * @param eduTeacherVo 讲师信息实体类
     * @return com.deke.vo.Result
     */
    @PostMapping("/qianaddTeacher")
    @ApiOperation(value = "添加的方法")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "eduTeacherVo",value = "讲师信息的实体类")
    })
    public Result qianaddTeacher(@RequestBody EduTeacherVo eduTeacherVo){
        return eduTeacherVoService.qianaddTeacher(eduTeacherVo);
    }


    /**
     * @create by: 张恒
     * @description: 添加头像
     * @create time: 2023/1/30 14:22
     * @param null
     * @return
     */
    @PostMapping(value = "uploadMsg")
    @ApiOperation(value = "添加头像")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "file",value = "文件",paramType = "form",dataType = "file",required = true)
    })
    public String uploadMsg(@RequestParam("file") MultipartFile file){
        String url = ossService.uploadFileAvatar(file);
        return url;
    }

    /**
     * @create by: 张恒
     * @description: 根据讲师名查询
     * @create time: 2023/1/30 14:23
     * @param null
     * @return
     */
    @PostMapping("queryAllTeacherByTeacherName/{teacherName}")
    @ApiOperation(value = "根据讲师名查询讲师信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "teacherName",value = "讲师名")
    })
    public Result queryAllTeacherByTeacherName(@PathVariable(value = "teacherName") String name){
        return eduTeacherVoService.queryAllTeacherByTeacherName(name);
    }

    /**
     * @create by: 张恒
     * @description: 根据id删除
     * @create time: 2023/1/30 14:23
     * @param null
     * @return
     */
    @PostMapping("deleteById/{id}")
    @ApiOperation(value = "删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "主键")
    })
    public Result deleteById(@PathVariable String id){
        return eduTeacherVoService.deleteById(id);
    }

}